package com.bcinfo.iccard.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;

public class TimeUtils
{
    // 获取下一年的日期
    public static Date nextYear(Timestamp currentDate)
    {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(currentDate);
        cal.add(GregorianCalendar.YEAR, 1);
        return cal.getTime();
    }

    public Timestamp getNextYear4Timestamp()
    {
        Timestamp c = new Timestamp(System.currentTimeMillis());
        Date date = TimeUtils.nextYear(c);
        // System.out.println(date);
        Timestamp ts = new Timestamp(date.getTime());
        // System.out.println(ts);
        return ts;
    }

    public static void main(String[] args) throws ParseException
    {
        // new TimeUtils().getNextYear4Timestamp();

        // DateFormat df = new SimpleDateFormat("dd-MM-yyyy");

    }

    public static int compareDatesByCompareTo(Timestamp oldDate, Timestamp newDate)
    {
        int result = 0;
        String oldD = DateUtil.getDate(oldDate);
        String newD = DateUtil.getDate(newDate);
        if (oldD.compareTo(newD) == 0)
        {
            result = 0;
        }
        else if (oldD.compareTo(newD) < 0)
        {
            result = 1;
        }
        else if (oldD.compareTo(newD) > 0)
        {
            result = 2;
        }
        // System.out.println("result=" + result);
        return result;
    }

}
